<?php
require_once('./includes/headers.inc.php');
require_once('./top.php');

$error = FALSE;
if(!isset($_GET['id'])) {
    header('Location: /notfound.php');
    exit();
}
$checkin_id = $_GET['id'];

if($_POST) {
    if($_POST['checkin_id'] == $_GET['id']) {
        $userMgr->deleteCheckin($_POST['checkin_id'], $_SESSION['user']['id']);
        $_SESSION['msg'] = $msgMgr->get('checkin-delete-success');
        header('Location: /viewuser.php?id=' . $_SESSION['user']['id']);
        exit();
    }
}

$checkin = $userMgr->getCheckin($checkin_id, $_SESSION['user']['id']);
if(!$checkin) {
    $error = $msgMgr->get('checkin-exist-error');
}
switch($checkin['completed']) {
    case 1:
        $completed = 'notcompleted';
        break;
    case 0:
        $completed = 'completed';
        break;
    default:
        $completed = 'blockcompleted';
        break;
}

$replaces = array(
    'id'                => $checkin_id,
    'user_id'           => $checkin['user_id'],
    'username'          => $checkin['username'],
    'location_id'       => $checkin['location_id'],
    'location'          => $checkin['location'],
    'timestamp'         => date('d-m-Y', strtotime($checkin['timestamp'])),
    'completed'         => $completed,
    'colour'            => $checkin['colour'],
    'route_id'          => $checkin['route_id'],
    'difficulty'        => $checkin['difficulty'],
    'is_short'          => ($checkin['is_short'] ? ' short' : ''),
    'name'              => $checkin['name'],
    'comment'           => ($checkin['comment'] ? '<li class="comment">' . $checkin['comment'] . '</li>' : ''),
    'error'             => $msgMgr->formatMsg($error),
);
$lang = array(
    'header_delete_checkin' => $langMgr->get('header_delete_checkin'),
    'text_delete_checkin'   => $langMgr->get('text_delete_checkin'),
    'btn_confirm'           => $langMgr->get('btn_confirm'),
);
$templateMgr->loadContent(basename(__FILE__, '.php'), array_merge($replaces, $lang));
?>
